package com.sgb.kjwl.view.ui.activity.ownerInfoNews;

import android.content.Context;
import android.content.Intent;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;

import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityOwnerInfoNewsBinding;
import com.sgb.kjwl.di.ownerInfoNews.DaggerOwnerInfoNewsComponent;
import com.sgb.kjwl.di.ownerInfoNews.OwnerInfoNewsModule;
import com.sgb.kjwl.model.entity.transport.GoodsInfoEntity3;
import com.sgb.kjwl.view.ui.adapter.owerInfoNews.OwerInfoNewsTypeAdapter;
import com.sgb.kjwl.viewmodel.ownerInfoNews.OwnerInfoNewsAtvModel;
import com.swgk.core.base.di.AppComponent;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

public class OwnerInfoNewsActivity extends AppActivity {
    @Inject
    OwnerInfoNewsAtvModel viewModel;

    ActivityOwnerInfoNewsBinding binding;

    private OwerInfoNewsTypeAdapter adapter;

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, OwnerInfoNewsActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void setupActivityComponent(AppComponent appComponent) {
        DaggerOwnerInfoNewsComponent.builder().appComponent(appComponent).ownerInfoNewsModule(new OwnerInfoNewsModule(this)).build().inject(this);
    }

    @Override
    protected void initView() {
        binding = DataBindingUtil.setContentView(this, R.layout.activity_owner_info_news);
        binding.setViewModel(viewModel);
        binding.include.ivBack.setOnClickListener(view -> finish());
        binding.include.titleView.setText("车主消息");
        List<GoodsInfoEntity3> list = new ArrayList<>();
        int page = 2;
        for (int i = 0; i < 10; i++) {
            GoodsInfoEntity3 needsEntity = new GoodsInfoEntity3();
            needsEntity.setStartStation("北京 朝阳_" + (i * page));
            needsEntity.setEndStation("上海 黄埔新区_" + (i * page));
            needsEntity.setGoodsName("金属刚才/10吨_" + (i * page));
            needsEntity.setDistances("已上架");
            if (i % 2 == 0) {
                needsEntity.setGoodsPrice("success");
            } else {
                needsEntity.setGoodsPrice("fail");
            }
            needsEntity.setGoodsType("2020-3-20/高栏/15m");

            list.add(needsEntity);
        }
        if (adapter == null) {
            adapter = new OwerInfoNewsTypeAdapter(getActivity(), list);
        }

        binding.owerMessageList.setLayoutManager(new GridLayoutManager(getActivity(), 1));
        binding.owerMessageList.setAdapter(adapter);
    }
}